<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>第2节：numpy数组基本 |数据分析课件</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../chapter1/03numpy数组操作.html" />
    
    
    <link rel="prev" href="../chapter1/01numpy库介绍.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="2.2"
        data-chapter-title="第2节：numpy数组基本"
        data-filepath="chapter1/02numpy数组基本.md"
        data-basepath=".."
        data-revision="Wed Jul 17 2019 11:42:54 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Introduction
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="chapter0/00.html">
            
                
                    <a href="../chapter0/00.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        第一章：数据分析前奏
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="chapter0/01什么是数据分析.html">
            
                
                    <a href="../chapter0/01什么是数据分析.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        第1节：什么是数据分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="chapter0/02环境搭建.html">
            
                
                    <a href="../chapter0/02环境搭建.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        第2节：环境搭建
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="chapter0/03jupyternotebook使用.html">
            
                
                    <a href="../chapter0/03jupyternotebook使用.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        第3节：jupyternotebook使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="chapter0/04作业.html">
            
                
                    <a href="../chapter0/04作业.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        第4节：作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="chapter1/00.html">
            
                
                    <a href="../chapter1/00.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        第二章：Numpy库
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="chapter1/01numpy库介绍.html">
            
                
                    <a href="../chapter1/01numpy库介绍.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        第1节：numpy库介绍
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="2.2" data-path="chapter1/02numpy数组基本.html">
            
                
                    <a href="../chapter1/02numpy数组基本.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        第2节：numpy数组基本
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="chapter1/03numpy数组操作.html">
            
                
                    <a href="../chapter1/03numpy数组操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        第3节：numpy数组操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="chapter1/03numpy索引和切片.html">
            
                
                    <a href="../chapter1/03numpy索引和切片.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        第4节：numpy索引和切片
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="chapter1/04Numpy索引和切片作业.html">
            
                
                    <a href="../chapter1/04Numpy索引和切片作业.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        第5节：Numpy索引和切片作业
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="chapter1/05numpy数组操作.html">
            
                
                    <a href="../chapter1/05numpy数组操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        第6节：numpy数组操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="chapter1/06深拷贝和浅拷贝.html">
            
                
                    <a href="../chapter1/06深拷贝和浅拷贝.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        第7节：深拷贝和浅拷贝
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="chapter1/07文件操作.html">
            
                
                    <a href="../chapter1/07文件操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        第8节：文件操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="chapter1/08数组操作和文件操作作业.html">
            
                
                    <a href="../chapter1/08数组操作和文件操作作业.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                        第9节：数组操作和文件操作作业.md
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="chapter1/09NAN和INF值处理.html">
            
                
                    <a href="../chapter1/09NAN和INF值处理.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.</b>
                        
                        第10节：NAN和INF值处理.md
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="chapter1/10random模块.html">
            
                
                    <a href="../chapter1/10random模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.</b>
                        
                        第11节：random模块.md
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="chapter1/11axis理解.html">
            
                
                    <a href="../chapter1/11axis理解.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.12.</b>
                        
                        第12节：axis理解.md
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="chapter1/12通用函数.html">
            
                
                    <a href="../chapter1/12通用函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.13.</b>
                        
                        第13节：通用函数.md
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="chapter1/13numpy练习题.html">
            
                
                    <a href="../chapter1/13numpy练习题.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.14.</b>
                        
                        第14节：numpy练习题.md
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="chapter2/00.html">
            
                
                    <a href="../chapter2/00.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        第三章：Pandas库
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="chapter2/01pandas介绍.html">
            
                
                    <a href="../chapter2/01pandas介绍.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        第1节：pandas介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="chapter2/02pandas索引操作.html">
            
                
                    <a href="../chapter2/02pandas索引操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        第2节：pandas索引操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="chapter2/03pandas对齐运算.html">
            
                
                    <a href="../chapter2/03pandas对齐运算.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        第3节：pandas对齐运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="chapter2/04pandas函数应用.html">
            
                
                    <a href="../chapter2/04pandas函数应用.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        第4节：pandas函数应用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="chapter2/05pandas层级索引.html">
            
                
                    <a href="../chapter2/05pandas层级索引.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        第5节：pandas层级索引
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="chapter2/06pandas统计计算和描述.html">
            
                
                    <a href="../chapter2/06pandas统计计算和描述.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        第6节：pandas统计计算和描述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="chapter2/07文件操作.html">
            
                
                    <a href="../chapter2/07文件操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        第7节：文件操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="chapter2/08数据清洗.html">
            
                
                    <a href="../chapter2/08数据清洗.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        第8节：数据清洗
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="chapter2/09聚合和分组.html">
            
                
                    <a href="../chapter2/09聚合和分组.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        第9节：聚合和分组
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="chapter2/10时间序列.html">
            
                
                    <a href="../chapter2/10时间序列.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        第10节：时间序列
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="chapter4/00.html">
            
                
                    <a href="../chapter4/00.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        第四章：Matploblib库
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="chapter4/01常用图.html">
            
                
                    <a href="../chapter4/01常用图.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        第1节：常用图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="chapter4/02基本使用.html">
            
                
                    <a href="../chapter4/02基本使用.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        第2节：基本使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="chapter4/03条形图.html">
            
                
                    <a href="../chapter4/03条形图.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        第3节：条形图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="chapter4/04直方图.html">
            
                
                    <a href="../chapter4/04直方图.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        第4节：直方图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="chapter4/05散点图.html">
            
                
                    <a href="../chapter4/05散点图.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        第5节：散点图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="chapter4/06饼图.html">
            
                
                    <a href="../chapter4/06饼图.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        第6节：饼图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="chapter4/07箱线图.html">
            
                
                    <a href="../chapter4/07箱线图.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.7.</b>
                        
                        第7节：箱线图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="chapter4/08雷达图.html">
            
                
                    <a href="../chapter4/08雷达图.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.8.</b>
                        
                        第8节：雷达图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="chapter4/09matplotlib绘图分析.html">
            
                
                    <a href="../chapter4/09matplotlib绘图分析.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.</b>
                        
                        第9节：matplotlib绘图分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.10" data-path="chapter4/10多图布局.html">
            
                
                    <a href="../chapter4/10多图布局.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.10.</b>
                        
                        第10节：多图布局
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.11" data-path="chapter4/11matplotlib配置.html">
            
                
                    <a href="../chapter4/11matplotlib配置.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.11.</b>
                        
                        第11节：matplotlib配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.12" data-path="chapter4/12matplotlib作业.html">
            
                
                    <a href="../chapter4/12matplotlib作业.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.12.</b>
                        
                        第12节：matplotlib作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="chapter5/00.html">
            
                
                    <a href="../chapter5/00.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        第五章：Seaborn库
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="chapter5/01关系绘图.html">
            
                
                    <a href="../chapter5/01关系绘图.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        第1节：关系绘图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="chapter5/02分类绘图.html">
            
                
                    <a href="../chapter5/02分类绘图.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        第2节：分类绘图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="chapter5/03分布绘图.html">
            
                
                    <a href="../chapter5/03分布绘图.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        第3节：分布绘图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="chapter5/04线性关系绘图.html">
            
                
                    <a href="../chapter5/04线性关系绘图.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        第4节：线性关系绘图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="chapter5/05FacetGrid结构图.html">
            
                
                    <a href="../chapter5/05FacetGrid结构图.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        第5节：FacetGrid结构图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="chapter5/06样式设置.html">
            
                
                    <a href="../chapter5/06样式设置.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        第6节：样式设置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="chapter5/07调色盘设置.html">
            
                
                    <a href="../chapter5/07调色盘设置.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        第7节：调色盘设置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="chapter5/08seaborn作业.html">
            
                
                    <a href="../chapter5/08seaborn作业.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        第8节：seaborn作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="chapter3/00.html">
            
                
                    <a href="../chapter3/00.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        第六章：统计分析强化
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="chapter3/01常用专业数学术语.html">
            
                
                    <a href="../chapter3/01常用专业数学术语.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        第1节：常用专业数学术语
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="chapter3/02平均数.html">
            
                
                    <a href="../chapter3/02平均数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        第2节：平均数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="chapter3/03方差和标准差.html">
            
                
                    <a href="../chapter3/03方差和标准差.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        第3节：方差和标准差
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="chapter3/04正态分布.html">
            
                
                    <a href="../chapter3/04正态分布.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        第4节：正态分布
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="chapter3/05对比分析.html">
            
                
                    <a href="../chapter3/05对比分析.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        第5节：对比分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="chapter3/06分布分析.html">
            
                
                    <a href="../chapter3/06分布分析.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        第6节：分布分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="chapter3/07交叉分析.html">
            
                
                    <a href="../chapter3/07交叉分析.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        第7节：交叉分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="chapter3/08统计分析.html">
            
                
                    <a href="../chapter3/08统计分析.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.8.</b>
                        
                        第8节：统计分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.9" data-path="chapter3/09帕累托分析.html">
            
                
                    <a href="../chapter3/09帕累托分析.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.9.</b>
                        
                        第9节：帕累托分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.10" data-path="chapter3/10矩阵关联分析.html">
            
                
                    <a href="../chapter3/10矩阵关联分析.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.10.</b>
                        
                        第10节：矩阵关联分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.11" data-path="chapter3/11综合性分析.html">
            
                
                    <a href="../chapter3/11综合性分析.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.11.</b>
                        
                        第11节：综合性分析
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="chapter6/00.html">
            
                
                    <a href="../chapter6/00.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        第七章：数据分析实战
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="chapter6/01App数据分析实战.html">
            
                
                    <a href="../chapter6/01App数据分析实战.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        第1节：App数据分析实战
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="chapter6/02心脏病患者数据分析.html">
            
                
                    <a href="../chapter6/02心脏病患者数据分析.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        第2节：心脏病患者数据分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="chapter6/03StackoverFlow数据分析.html">
            
                
                    <a href="../chapter6/03StackoverFlow数据分析.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        第3节：StackoverFlow数据分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="chapter6/04二手房数据分析.html">
            
                
                    <a href="../chapter6/04二手房数据分析.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        第4节：二手房数据分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="chapter6/05吃鸡数据分析.html">
            
                
                    <a href="../chapter6/05吃鸡数据分析.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.5.</b>
                        
                        第5节：吃鸡数据分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="chapter6/06黑色星期五数据分析.html">
            
                
                    <a href="../chapter6/06黑色星期五数据分析.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.6.</b>
                        
                        第6节：黑色星期五数据分析
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" data-path="chapter7/00.html">
            
                
                    <a href="../chapter7/00.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        第八章：补充
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="chapter7/01用Excel做数据分析.html">
            
                
                    <a href="../chapter7/01用Excel做数据分析.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        第1节：用Excel做数据分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="chapter7/02echarts和pyecharts库.html">
            
                
                    <a href="../chapter7/02echarts和pyecharts库.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        第2节：echarts和pyecharts库
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="chapter7/03bokeh库.html">
            
                
                    <a href="../chapter7/03bokeh库.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        第3节：bokeh库
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="numpy&#x6570;&#x7EC4;&#x57FA;&#x672C;&#x7528;&#x6CD5;">NumPy&#x6570;&#x7EC4;&#x57FA;&#x672C;&#x7528;&#x6CD5;</h1>
<ol>
<li><code>Numpy</code>&#x662F;<code>Python</code>&#x79D1;&#x5B66;&#x8BA1;&#x7B97;&#x5E93;&#xFF0C;&#x7528;&#x4E8E;&#x5FEB;&#x901F;&#x5904;&#x7406;&#x4EFB;&#x610F;&#x7EF4;&#x5EA6;&#x7684;&#x6570;&#x7EC4;&#x3002;</li>
<li><code>NumPy</code>&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;<strong>N&#x7EF4;&#x6570;&#x7EC4;&#x7C7B;&#x578B;ndarray</strong>&#xFF0C;&#x5B83;&#x63CF;&#x8FF0;&#x4E86;<strong>&#x76F8;&#x540C;&#x7C7B;&#x578B;</strong>&#x7684;&#x201C;items&#x201D;&#x7684;&#x96C6;&#x5408;&#x3002;</li>
<li><code>numpy.ndarray</code>&#x652F;&#x6301;&#x5411;&#x91CF;&#x5316;&#x8FD0;&#x7B97;&#x3002;</li>
<li><code>NumPy</code>&#x4F7F;&#x7528;c&#x8BED;&#x8A00;&#x5199;&#x7684;&#xFF0C;&#x5E95;&#x90E8;&#x89E3;&#x9664;&#x4E86;<code>GIL</code>&#xFF0C;&#x5176;&#x5BF9;&#x6570;&#x7EC4;&#x7684;&#x64CD;&#x4F5C;&#x901F;&#x5EA6;&#x4E0D;&#x5728;&#x53D7;<code>python</code>&#x89E3;&#x91CA;&#x5668;&#x9650;&#x5236;&#x3002;</li>
</ol>
<h2 id="numpy&#x4E2D;&#x7684;&#x6570;&#x7EC4;&#xFF1A;">numpy&#x4E2D;&#x7684;&#x6570;&#x7EC4;&#xFF1A;</h2>
<p><code>Numpy</code>&#x4E2D;&#x7684;&#x6570;&#x7EC4;&#x7684;&#x4F7F;&#x7528;&#x8DDF;<code>Python</code>&#x4E2D;&#x7684;&#x5217;&#x8868;&#x975E;&#x5E38;&#x7C7B;&#x4F3C;&#x3002;&#x4ED6;&#x4EEC;&#x4E4B;&#x95F4;&#x7684;&#x533A;&#x522B;&#x5982;&#x4E0B;&#xFF1A;  </p>
<ol>
<li>&#x4E00;&#x4E2A;&#x5217;&#x8868;&#x4E2D;&#x53EF;&#x4EE5;&#x5B58;&#x50A8;&#x591A;&#x79CD;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x3002;&#x6BD4;&#x5982;<code>a = [1,&apos;a&apos;]</code>&#x662F;&#x5141;&#x8BB8;&#x7684;&#xFF0C;&#x800C;&#x6570;&#x7EC4;&#x53EA;&#x80FD;&#x5B58;&#x50A8;&#x540C;&#x79CD;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x3002;  </li>
<li>&#x6570;&#x7EC4;&#x53EF;&#x4EE5;&#x662F;&#x591A;&#x7EF4;&#x7684;&#xFF0C;&#x5F53;&#x591A;&#x7EF4;&#x6570;&#x7EC4;&#x4E2D;&#x6240;&#x6709;&#x7684;&#x6570;&#x636E;&#x90FD;&#x662F;&#x6570;&#x503C;&#x7C7B;&#x578B;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;&#x7EBF;&#x6027;&#x4EE3;&#x6570;&#x4E2D;&#x7684;&#x77E9;&#x9635;&#xFF0C;&#x662F;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x76F8;&#x4E92;&#x95F4;&#x7684;&#x8FD0;&#x7B97;&#x7684;&#x3002;</li>
</ol>
<h2 id="&#x521B;&#x5EFA;&#x6570;&#x7EC4;&#xFF08;npndarray&#x5BF9;&#x8C61;&#xFF09;&#xFF1A;">&#x521B;&#x5EFA;&#x6570;&#x7EC4;&#xFF08;np.ndarray&#x5BF9;&#x8C61;&#xFF09;&#xFF1A;</h2>
<p><code>Numpy</code>&#x7ECF;&#x5E38;&#x548C;&#x6570;&#x7EC4;&#x6253;&#x4EA4;&#x9053;&#xFF0C;&#x56E0;&#x6B64;&#x9996;&#x5148;&#x7B2C;&#x4E00;&#x6B65;&#x662F;&#x8981;&#x5B66;&#x4F1A;&#x521B;&#x5EFA;&#x6570;&#x7EC4;&#x3002;&#x5728;<code>Numpy</code>&#x4E2D;&#x7684;&#x6570;&#x7EC4;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x53EB;&#x505A;<code>ndarray</code>&#x3002;&#x4EE5;&#x4E0B;&#x662F;&#x4E24;&#x79CD;&#x521B;&#x5EFA;&#x7684;&#x65B9;&#x5F0F;&#xFF1A;</p>
<ol>
<li><p>&#x6839;&#x636E;<code>Python</code>&#x4E2D;&#x7684;&#x5217;&#x8868;&#x751F;&#x6210;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
a1 = np.array([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>])
print(a1)
print(type(a1))
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528;<code>np.arange</code>&#x751F;&#x6210;&#xFF0C;<code>np.arange</code>&#x7684;&#x7528;&#x6CD5;&#x7C7B;&#x4F3C;&#x4E8E;<code>Python</code>&#x4E2D;&#x7684;<code>range</code>&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
a2 = np.arange(<span class="hljs-number">2</span>,<span class="hljs-number">21</span>,<span class="hljs-number">2</span>)
print(a2)
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528;<code>np.random</code>&#x751F;&#x6210;&#x968F;&#x673A;&#x6570;&#x7684;&#x6570;&#x7EC4;&#xFF1A;</p>
<pre><code class="lang-python">a1 = np.random.random(<span class="hljs-number">2</span>,<span class="hljs-number">2</span>) <span class="hljs-comment"># &#x751F;&#x6210;2&#x884C;2&#x5217;&#x7684;&#x968F;&#x673A;&#x6570;&#x7684;&#x6570;&#x7EC4;</span>
a2 = np.random.randint(<span class="hljs-number">0</span>,<span class="hljs-number">10</span>,size=(<span class="hljs-number">3</span>,<span class="hljs-number">3</span>)) <span class="hljs-comment"># &#x5143;&#x7D20;&#x662F;&#x4ECE;0-10&#x4E4B;&#x95F4;&#x968F;&#x673A;&#x7684;3&#x884C;3&#x5217;&#x7684;&#x6570;&#x7EC4;</span>
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528;&#x51FD;&#x6570;&#x751F;&#x6210;&#x7279;&#x6B8A;&#x7684;&#x6570;&#x7EC4;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
a1 = np.zeros((<span class="hljs-number">2</span>,<span class="hljs-number">2</span>)) <span class="hljs-comment">#&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x6240;&#x6709;&#x5143;&#x7D20;&#x90FD;&#x662F;0&#x7684;2&#x884C;2&#x5217;&#x7684;&#x6570;&#x7EC4;</span>
a2 = np.ones((<span class="hljs-number">3</span>,<span class="hljs-number">2</span>)) <span class="hljs-comment">#&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x6240;&#x6709;&#x5143;&#x7D20;&#x90FD;&#x662F;1&#x7684;3&#x884C;2&#x5217;&#x7684;&#x6570;&#x7EC4;</span>
a3 = np.full((<span class="hljs-number">2</span>,<span class="hljs-number">2</span>),<span class="hljs-number">8</span>) <span class="hljs-comment">#&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x6240;&#x6709;&#x5143;&#x7D20;&#x90FD;&#x662F;8&#x7684;2&#x884C;2&#x5217;&#x7684;&#x6570;&#x7EC4;</span>
a4 = np.eye(<span class="hljs-number">3</span>) <span class="hljs-comment">#&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x5728;&#x659C;&#x65B9;&#x5F62;&#x4E0A;&#x5143;&#x7D20;&#x4E3A;1&#xFF0C;&#x5176;&#x4ED6;&#x5143;&#x7D20;&#x90FD;&#x4E3A;0&#x7684;3x3&#x7684;&#x77E9;&#x9635;</span>
</code></pre>
</li>
</ol>
<h2 id="ndarray&#x5E38;&#x7528;&#x5C5E;&#x6027;&#xFF1A;">ndarray&#x5E38;&#x7528;&#x5C5E;&#x6027;&#xFF1A;</h2>
<h3 id="ndarraydtype&#xFF1A;"><code>ndarray.dtype</code>&#xFF1A;</h3>
<p>&#x56E0;&#x4E3A;&#x6570;&#x7EC4;&#x4E2D;&#x53EA;&#x80FD;&#x5B58;&#x50A8;&#x540C;&#x4E00;&#x79CD;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x56E0;&#x6B64;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>dtype</code>&#x83B7;&#x53D6;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x3002;&#x4EE5;&#x4E0B;&#x662F;<code>ndarray.dtype</code>&#x7684;&#x5E38;&#x7528;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x6570;&#x636E;&#x7C7B;&#x578B;</th>
<th>&#x63CF;&#x8FF0;</th>
<th>&#x552F;&#x4E00;&#x6807;&#x8BC6;&#x7B26;</th>
</tr>
</thead>
<tbody>
<tr>
<td>bool</td>
<td>&#x7528;&#x4E00;&#x4E2A;&#x5B57;&#x8282;&#x5B58;&#x50A8;&#x7684;&#x5E03;&#x5C14;&#x7C7B;&#x578B;&#xFF08;True&#x6216;False&#xFF09;</td>
<td>&apos;b&apos;</td>
</tr>
<tr>
<td>int8</td>
<td>&#x4E00;&#x4E2A;&#x5B57;&#x8282;&#x5927;&#x5C0F;&#xFF0C;-128 &#x81F3; 127</td>
<td>&apos;i1&apos;</td>
</tr>
<tr>
<td>int16</td>
<td>&#x6574;&#x6570;&#xFF0C;16 &#x4F4D;&#x6574;&#x6570;(-32768 ~ 32767)</td>
<td>&apos;i2&apos;</td>
</tr>
<tr>
<td>int32</td>
<td>&#x6574;&#x6570;&#xFF0C;32 &#x4F4D;&#x6574;&#x6570;(-2147483648 ~ 2147483647)</td>
<td>&apos;i4&apos;</td>
</tr>
<tr>
<td>int64</td>
<td>&#x6574;&#x6570;&#xFF0C;64 &#x4F4D;&#x6574;&#x6570;(-9223372036854775808 ~ 9223372036854775807)</td>
<td>&apos;i8&apos;</td>
</tr>
<tr>
<td>uint8</td>
<td>&#x65E0;&#x7B26;&#x53F7;&#x6574;&#x6570;&#xFF0C;0 &#x81F3; 255</td>
<td>&apos;u1&apos;</td>
</tr>
<tr>
<td>uint16</td>
<td>&#x65E0;&#x7B26;&#x53F7;&#x6574;&#x6570;&#xFF0C;0 &#x81F3; 65535</td>
<td>&apos;u2&apos;</td>
</tr>
<tr>
<td>uint32</td>
<td>&#x65E0;&#x7B26;&#x53F7;&#x6574;&#x6570;&#xFF0C;0 &#x81F3; 2 ** 32 - 1</td>
<td>&apos;u4&apos;</td>
</tr>
<tr>
<td>uint64</td>
<td>&#x65E0;&#x7B26;&#x53F7;&#x6574;&#x6570;&#xFF0C;0 &#x81F3; 2 ** 64 - 1</td>
<td>&apos;u8&apos;</td>
</tr>
<tr>
<td>float16</td>
<td>&#x534A;&#x7CBE;&#x5EA6;&#x6D6E;&#x70B9;&#x6570;&#xFF1A;16&#x4F4D;&#xFF0C;&#x6B63;&#x8D1F;&#x53F7;1&#x4F4D;&#xFF0C;&#x6307;&#x6570;5&#x4F4D;&#xFF0C;&#x7CBE;&#x5EA6;10&#x4F4D;</td>
<td>&apos;f2&apos;</td>
</tr>
<tr>
<td>float32</td>
<td>&#x5355;&#x7CBE;&#x5EA6;&#x6D6E;&#x70B9;&#x6570;&#xFF1A;32&#x4F4D;&#xFF0C;&#x6B63;&#x8D1F;&#x53F7;1&#x4F4D;&#xFF0C;&#x6307;&#x6570;8&#x4F4D;&#xFF0C;&#x7CBE;&#x5EA6;23&#x4F4D;</td>
<td>&apos;f4&apos;</td>
</tr>
<tr>
<td>float64</td>
<td>&#x53CC;&#x7CBE;&#x5EA6;&#x6D6E;&#x70B9;&#x6570;&#xFF1A;64&#x4F4D;&#xFF0C;&#x6B63;&#x8D1F;&#x53F7;1&#x4F4D;&#xFF0C;&#x6307;&#x6570;11&#x4F4D;&#xFF0C;&#x7CBE;&#x5EA6;52&#x4F4D;</td>
<td>&apos;f8&apos;</td>
</tr>
<tr>
<td>complex64</td>
<td>&#x590D;&#x6570;&#xFF0C;&#x5206;&#x522B;&#x7528;&#x4E24;&#x4E2A;32&#x4F4D;&#x6D6E;&#x70B9;&#x6570;&#x8868;&#x793A;&#x5B9E;&#x90E8;&#x548C;&#x865A;&#x90E8;</td>
<td>&apos;c8&apos;</td>
</tr>
<tr>
<td>complex128</td>
<td>&#x590D;&#x6570;&#xFF0C;&#x5206;&#x522B;&#x7528;&#x4E24;&#x4E2A;64&#x4F4D;&#x6D6E;&#x70B9;&#x6570;&#x8868;&#x793A;&#x5B9E;&#x90E8;&#x548C;&#x865A;&#x90E8;</td>
<td>&apos;c16&apos;</td>
</tr>
<tr>
<td>object_</td>
<td>python&#x5BF9;&#x8C61;</td>
<td>&apos;O&apos;</td>
</tr>
<tr>
<td>string_</td>
<td>&#x5B57;&#x7B26;&#x4E32;</td>
<td>&apos;S&apos;</td>
</tr>
<tr>
<td>unicode_</td>
<td>unicode&#x7C7B;&#x578B;</td>
<td>&apos;U&apos;</td>
</tr>
</tbody>
</table>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;<code>Numpy</code>&#x4E2D;&#x5173;&#x4E8E;&#x6570;&#x503C;&#x7684;&#x7C7B;&#x578B;&#x6BD4;<code>Python</code>&#x5185;&#x7F6E;&#x7684;&#x591A;&#x5F97;&#x591A;&#xFF0C;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;<code>Numpy</code>&#x4E3A;&#x4E86;&#x80FD;&#x9AD8;&#x6548;&#x5904;&#x7406;&#x5904;&#x7406;&#x6D77;&#x91CF;&#x6570;&#x636E;&#x800C;&#x8BBE;&#x8BA1;&#x7684;&#x3002;&#x4E3E;&#x4E2A;&#x4F8B;&#x5B50;&#xFF0C;&#x6BD4;&#x5982;&#x73B0;&#x5728;&#x60F3;&#x8981;&#x5B58;&#x50A8;&#x4E0A;&#x767E;&#x4EBF;&#x7684;&#x6570;&#x5B57;&#xFF0C;&#x5E76;&#x4E14;&#x8FD9;&#x4E9B;&#x6570;&#x5B57;&#x90FD;&#x4E0D;&#x8D85;&#x8FC7;254&#xFF08;&#x4E00;&#x4E2A;&#x5B57;&#x8282;&#x5185;&#xFF09;&#xFF0C;&#x6211;&#x4EEC;&#x5C31;&#x53EF;&#x4EE5;&#x5C06;<code>dtype</code>&#x8BBE;&#x7F6E;&#x4E3A;<code>int8</code>&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x6BD4;&#x9ED8;&#x8BA4;&#x4F7F;&#x7528;<code>int64</code>&#x66F4;&#x80FD;&#x8282;&#x7701;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#x4E86;&#x3002;&#x7C7B;&#x578B;&#x76F8;&#x5173;&#x7684;&#x64CD;&#x4F5C;&#x5982;&#x4E0B;&#xFF1A;</p>
<ol>
<li>&#x9ED8;&#x8BA4;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF1A;<pre><code class="lang-python"><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
a1 = np.array([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>])
print(a1.dtype) 
<span class="hljs-comment"># &#x5982;&#x679C;&#x662F;windows&#x7CFB;&#x7EDF;&#xFF0C;&#x9ED8;&#x8BA4;&#x662F;int32</span>
<span class="hljs-comment"># &#x5982;&#x679C;&#x662F;mac&#x6216;&#x8005;linux&#x7CFB;&#x7EDF;&#xFF0C;&#x5219;&#x6839;&#x636E;&#x7CFB;&#x7EDF;&#x6765;</span>
</code></pre>
</li>
<li>&#x6307;&#x5B9A;<code>dtype</code>&#xFF1A;<pre><code class="lang-python"><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
a1 = np.array([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>],dtype=np.int64)
<span class="hljs-comment"># &#x6216;&#x8005; a1 = np.array([1,2,3],dtype=&quot;i8&quot;)</span>
print(a1.dtype)
</code></pre>
</li>
<li>&#x4FEE;&#x6539;<code>dtype</code>&#xFF1A;<pre><code class="lang-python"><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
a1 = np.array([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>])
print(a1.dtype) <span class="hljs-comment"># window&#x7CFB;&#x7EDF;&#x4E0B;&#x9ED8;&#x8BA4;&#x662F;int32</span>
<span class="hljs-comment"># &#x4EE5;&#x4E0B;&#x4FEE;&#x6539;dtype</span>
a2 = a1.astype(np.int64) <span class="hljs-comment"># astype&#x4E0D;&#x4F1A;&#x4FEE;&#x6539;&#x6570;&#x7EC4;&#x672C;&#x8EAB;&#xFF0C;&#x800C;&#x662F;&#x4F1A;&#x5C06;&#x4FEE;&#x6539;&#x540E;&#x7684;&#x7ED3;&#x679C;&#x8FD4;&#x56DE;</span>
print(a2.dtype)
</code></pre>
</li>
</ol>
<h3 id="ndarraysize&#xFF1A;"><code>ndarray.size</code>&#xFF1A;</h3>
<p>&#x83B7;&#x53D6;&#x6570;&#x7EC4;&#x4E2D;&#x603B;&#x7684;&#x5143;&#x7D20;&#x7684;&#x4E2A;&#x6570;&#x3002;&#x6BD4;&#x5982;&#x6709;&#x4E2A;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#xFF1A;</p>
<pre><code class="lang-python">   <span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
   a1 = np.array([[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>],[<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>]])
   print(a1.size) <span class="hljs-comment">#&#x6253;&#x5370;&#x7684;&#x662F;6&#xFF0C;&#x56E0;&#x4E3A;&#x603B;&#x5171;&#x6709;6&#x4E2A;&#x5143;&#x7D20;</span>
</code></pre>
<h3 id="ndarrayndim&#xFF1A;"><code>ndarray.ndim</code>&#xFF1A;</h3>
<p>&#x6570;&#x7EC4;&#x7684;&#x7EF4;&#x6570;&#x3002;&#x6BD4;&#x5982;&#xFF1A;</p>
<pre><code class="lang-python">   a1 = np.array([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>])
   print(a1.ndim) <span class="hljs-comment"># &#x7EF4;&#x5EA6;&#x4E3A;1</span>
   a2 = np.array([[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>],[<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>]])
   print(a2.ndim) <span class="hljs-comment"># &#x7EF4;&#x5EA6;&#x4E3A;2</span>
   a3 = np.array([[[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>],[<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>]],[[<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>],[<span class="hljs-number">10</span>,<span class="hljs-number">11</span>,<span class="hljs-number">12</span>]]])
   print(a3.ndim) <span class="hljs-comment"># &#x7EF4;&#x5EA6;&#x4E3A;3</span>
</code></pre>
<h3 id="ndarrayshape&#xFF1A;"><code>ndarray.shape</code>&#xFF1A;</h3>
<p>&#x6570;&#x7EC4;&#x7684;&#x7EF4;&#x5EA6;&#x7684;&#x5143;&#x7EC4;&#x3002;&#x6BD4;&#x5982;&#x4EE5;&#x4E0B;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-python">   a1 = np.array([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>])
   print(a1.shape) <span class="hljs-comment"># &#x8F93;&#x51FA;(3,)&#xFF0C;&#x610F;&#x601D;&#x662F;&#x4E00;&#x7EF4;&#x6570;&#x7EC4;&#xFF0C;&#x6709;3&#x4E2A;&#x6570;&#x636E;</span>

   a2 = np.array([[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>],[<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>]])
   print(a2.shape) <span class="hljs-comment"># &#x8F93;&#x51FA;(2,3)&#xFF0C;&#x610F;&#x601D;&#x662F;&#x4E8C;&#x4F4D;&#x6570;&#x7EC4;&#xFF0C;2&#x884C;3&#x5217;</span>

   a3 = np.array([
       [
           [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>],
           [<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>]
       ],
       [
           [<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>],
           [<span class="hljs-number">10</span>,<span class="hljs-number">11</span>,<span class="hljs-number">12</span>]
       ]
   ])
   print(a3.shape) <span class="hljs-comment"># &#x8F93;&#x51FA;(2,2,3)&#xFF0C;&#x610F;&#x601D;&#x662F;&#x4E09;&#x7EF4;&#x6570;&#x7EC4;&#xFF0C;&#x603B;&#x5171;&#x6709;2&#x4E2A;&#x5143;&#x7D20;&#xFF0C;&#x6BCF;&#x4E2A;&#x5143;&#x7D20;&#x662F;2&#x884C;3&#x5217;&#x7684;</span>

   a44 = np.array([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>],[<span class="hljs-number">4</span>,<span class="hljs-number">5</span>])
   print(a4.shape) <span class="hljs-comment"># &#x8F93;&#x51FA;(2,)&#xFF0C;&#x610F;&#x601D;&#x662F;a4&#x662F;&#x4E00;&#x4E2A;&#x4E00;&#x7EF4;&#x6570;&#x7EC4;&#xFF0C;&#x603B;&#x5171;&#x6709;2&#x5217;</span>
   print(a4) <span class="hljs-comment"># &#x8F93;&#x51FA;[list([1, 2, 3]) list([4, 5])]&#xFF0C;&#x5176;&#x4E2D;&#x6700;&#x5916;&#x9762;&#x5C42;&#x662F;&#x6570;&#x7EC4;&#xFF0C;&#x91CC;&#x9762;&#x662F;Python&#x5217;&#x8868;</span>
</code></pre>
<p>&#x53E6;&#x5916;&#xFF0C;&#x6211;&#x4EEC;&#x8FD8;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>ndarray.reshape</code>&#x6765;&#x91CD;&#x65B0;&#x4FEE;&#x6539;&#x6570;&#x7EC4;&#x7684;&#x7EF4;&#x6570;&#x3002;&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-python">   a1 = np.arange(<span class="hljs-number">12</span>) <span class="hljs-comment">#&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x6709;12&#x4E2A;&#x6570;&#x636E;&#x7684;&#x4E00;&#x7EF4;&#x6570;&#x7EC4;</span>
   print(a1) 

   a2 = a1.reshape((<span class="hljs-number">3</span>,<span class="hljs-number">4</span>)) <span class="hljs-comment">#&#x53D8;&#x6210;&#x4E00;&#x4E2A;2&#x7EF4;&#x6570;&#x7EC4;&#xFF0C;&#x662F;3&#x884C;4&#x5217;&#x7684;</span>
   print(a2)

   a3 = a1.reshape((<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">2</span>)) <span class="hljs-comment">#&#x53D8;&#x6210;&#x4E00;&#x4E2A;3&#x7EF4;&#x6570;&#x7EC4;&#xFF0C;&#x603B;&#x5171;&#x6709;2&#x5757;&#xFF0C;&#x6BCF;&#x4E00;&#x5757;&#x662F;2&#x884C;2&#x5217;&#x7684;</span>
   print(a3)

   a4 = a2.reshape((<span class="hljs-number">12</span>,)) <span class="hljs-comment"># &#x5C06;a2&#x7684;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#x91CD;&#x65B0;&#x53D8;&#x6210;&#x4E00;&#x4E2A;12&#x5217;&#x7684;1&#x7EF4;&#x6570;&#x7EC4;</span>
   print(a4)

   a5 = a2.flatten() <span class="hljs-comment"># &#x4E0D;&#x7BA1;a2&#x662F;&#x51E0;&#x7EF4;&#x6570;&#x7EC4;&#xFF0C;&#x90FD;&#x5C06;&#x4ED6;&#x53D8;&#x6210;&#x4E00;&#x4E2A;&#x4E00;&#x7EF4;&#x6570;&#x7EC4;</span>
   print(a5)
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF0C;<code>reshape</code>&#x5E76;&#x4E0D;&#x4F1A;&#x4FEE;&#x6539;&#x539F;&#x6765;&#x6570;&#x7EC4;&#x672C;&#x8EAB;&#xFF0C;&#x800C;&#x662F;&#x4F1A;&#x5C06;&#x4FEE;&#x6539;&#x540E;&#x7684;&#x7ED3;&#x679C;&#x8FD4;&#x56DE;&#x3002;&#x5982;&#x679C;&#x60F3;&#x8981;&#x76F4;&#x63A5;&#x4FEE;&#x6539;&#x6570;&#x7EC4;&#x672C;&#x8EAB;&#xFF0C;&#x90A3;&#x4E48;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>resize</code>&#x6765;&#x66FF;&#x4EE3;<code>reshape</code>&#x3002;</p>
<h3 id="ndarrayitemsize&#xFF1A;"><code>ndarray.itemsize</code>&#xFF1A;</h3>
<p>&#x6570;&#x7EC4;&#x4E2D;&#x6BCF;&#x4E2A;&#x5143;&#x7D20;&#x5360;&#x7684;&#x5927;&#x5C0F;&#xFF0C;&#x5355;&#x4F4D;&#x662F;&#x5B57;&#x8282;&#x3002;&#x6BD4;&#x5982;&#x4EE5;&#x4E0B;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-python">   a1 = np.array([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>],dtype=np.int32)
   print(a1.itemsize) <span class="hljs-comment"># &#x6253;&#x5370;4&#xFF0C;&#x56E0;&#x4E3A;&#x6BCF;&#x4E2A;&#x5B57;&#x8282;&#x662F;8&#x4F4D;&#xFF0C;32&#x4F4D;/8=4&#x4E2A;&#x5B57;&#x8282;</span>
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../chapter1/01numpy库介绍.html" class="navigation navigation-prev " aria-label="Previous page: 第1节：numpy库介绍"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../chapter1/03numpy数组操作.html" class="navigation navigation-next " aria-label="Next page: 第3节：numpy数组操作"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
